package com.common.base.util;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;


public class ApplicationContextListener implements ServletContextListener {

	protected final Log logger = LogFactory.getLog(this.getClass());
	
	public void contextDestroyed(ServletContextEvent sce) {
		logger.info("------Application Close...");
	}

	public void contextInitialized(ServletContextEvent sce) {
		
		logger.info("------Application Start...");
		
    	try {
			ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
			ServiceHelper.setApplicationContext(applicationContext);
		} catch (Exception e) {
			logger.error("------Application Error..." + e.toString());
		}
	}
}
